﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using HZ.Supervise.Model.Enum;
using HZ.Supervise.IBLL;
using System.Collections.Generic;
using HZ.Supervise.Model;

namespace HZ.Supervise.Web.Secondphase.NewReport
{
    public partial class GoodsPSLList : BasePage
    {
        public GoodsPSLList()
        {
            this.ModuleNo = Module.药品统计分析.ToString();
            this.PageOperateType = OperateType.药品汇总统计.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.AreaControl1.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;
                BindData();
                BindData_huizong();
            }
        }

        /// <summary>
        /// 查询方法
        /// 查询修改
        /// modify by张雄 
        /// </summary>
        public void BindData()
        {
            int t = 0;
            StringBuilder sb = new StringBuilder();
            string orderby = this.OrderFileds.SelectedValue + "  " + this.OrderType.SelectedValue;//排序字段与方式


            if (!string.IsNullOrEmpty(AreaControl1.SelectedAreaID) && AreaControl1.SelectedAreaID != "510000")
            {
                if (AreaControl1.SelectedAreaID.Length==4)
                {
                    sb.AppendFormat(" AND areaid like '{0}%'", AreaControl1.SelectedAreaID);
                }
                else
                {
                    sb.AppendFormat(" AND areaid ='{0}'", AreaControl1.SelectedAreaID);
                }
            }
            if (!string.IsNullOrEmpty(txtProductName.Text.ToString()))
            {
                sb.AppendFormat(" and ProductName like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtProductName.Text.ToString()));
            }
            if (!string.IsNullOrEmpty(txtMedicineModel.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and MedicineModelName like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtMedicineModel.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtPack.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and Pack like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtPack.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtCompany_SC.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and CompanyName_SC like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtCompany_SC.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtUnit.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and Unit = '{0}'", HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.ToString().Trim()));
            }

            HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
            System.Data.DataTable dt = iEC.getGoodsPSLList(0,sb.ToString(), orderby, this.AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out t);
            AspNetPager1.RecordCount = t;
            gvwXianQuInfo.PageSize = AspNetPager1.PageSize;
            this.gvwXianQuInfo.DataSource = dt;
            HZ.Supervise.Web.Function.ChangeRate_PS(dt, "DistributeRate");
            HZ.Supervise.Web.Function.ChangeRate(dt, "WareHouseRate");
            //HZ.Supervise.Web.Function.AddColumn(dt, "WareHouseRate", "SortSource");
            this.gvwXianQuInfo.DataBind();
 
        }
        /// <summary>
        /// 导出
        /// create by 张雄  2011.5.5
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnExcel_Click(object sender, EventArgs e)
        {
            int t = 0;
            StringBuilder sb = new StringBuilder();
            string orderby = this.OrderFileds.SelectedValue + "  " + this.OrderType.SelectedValue;//排序字段与方式

            if (!string.IsNullOrEmpty(AreaControl1.SelectedAreaID) && AreaControl1.SelectedAreaID != "510000")
            {
                if (AreaControl1.SelectedAreaID.Length == 4)
                {
                    sb.AppendFormat(" AND areaid like '{0}%'", AreaControl1.SelectedAreaID);
                }
                else
                {
                    sb.AppendFormat(" AND areaid ='{0}'", AreaControl1.SelectedAreaID);
                }
            }
            if (!string.IsNullOrEmpty(txtProductName.Text.ToString()))
            {
                sb.AppendFormat(" and ProductName like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtProductName.Text.ToString()));
            }
            if (!string.IsNullOrEmpty(txtMedicineModel.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and MedicineModelName like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtMedicineModel.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtPack.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and Pack like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtPack.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtCompany_SC.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and CompanyName_SC like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtCompany_SC.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtUnit.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and Unit = '{0}'", HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.ToString().Trim()));
            }
            HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
            System.Data.DataTable dt = iEC.getGoodsPSLList(0, sb.ToString(), orderby, 0, 0, out t);
            HZ.Supervise.Web.Function.ChangeRate_PS(dt, "DistributeRate");
            HZ.Supervise.Web.Function.AddColumn(dt, "WareHouseRate", "SortSource");
            ExportFile.Instance.ExportData(dt, gvwXianQuInfo, this.Page);
        }
        /// <summary>
        /// 分页
        /// by张雄
        /// </summary>
        /// <param name="sender">事件发送源</param>
        /// <param name="e">事件参数</param>
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
            this.divTable.Visible = true;
            this.divTable.Attributes.Add("style", "display:block;");
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>document.getElementById(\"btnShowImg\").value = \"隐藏县区数据\";</script>");
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
            AspNetPager2.CurrentPageIndex = 1;
        }


        /// <summary>
        /// 不分地区汇总后的数据
        /// </summary>
        public void BindData_huizong()
        {
            int t = 0;
            StringBuilder sb = new StringBuilder();
            string orderby = this.OrderFileds.SelectedValue + "  " + this.OrderType.SelectedValue;//排序字段与方式


            if (!string.IsNullOrEmpty(AreaControl1.SelectedAreaID) && AreaControl1.SelectedAreaID != "510000")
            {
                if (AreaControl1.SelectedAreaID.Length == 4)
                {
                    sb.AppendFormat(" AND areaid like '{0}%'", AreaControl1.SelectedAreaID);
                }
                else
                {
                    sb.AppendFormat(" AND areaid ='{0}'", AreaControl1.SelectedAreaID);
                }
            }
            if (!string.IsNullOrEmpty(txtProductName.Text.ToString()))
            {
                sb.AppendFormat(" and ProductName like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtProductName.Text.ToString()));
            }
            if (!string.IsNullOrEmpty(txtMedicineModel.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and MedicineModelName like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtMedicineModel.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtPack.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and Pack like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtPack.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtCompany_SC.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and CompanyName_SC like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtCompany_SC.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtUnit.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and Unit = '{0}'", HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.ToString().Trim()));
            }

            HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
            System.Data.DataTable dt = iEC.getGoodsPSLList(1, sb.ToString(), orderby, this.AspNetPager2.CurrentPageIndex, AspNetPager2.PageSize, out t);
            AspNetPager2.RecordCount = t;
            gvwGoodsTotal.PageSize = AspNetPager2.PageSize;
            this.gvwGoodsTotal.DataSource = dt;
            HZ.Supervise.Web.Function.ChangeRate_PS(dt, "DistributeRate");
            HZ.Supervise.Web.Function.ChangeRate(dt, "WareHouseRate");
            //HZ.Supervise.Web.Function.AddColumn(dt, "WareHouseRate", "SortSource");
            this.gvwGoodsTotal.DataBind();
        }
        /// <summary>
        /// 不分地区汇总后的数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void AspNetPager2_PageChanged(object sender, EventArgs e)
        {
            BindData_huizong();
            this.divTable.Visible = true;
            this.divTable.Attributes.Add("style", "display:block;");
            this.Page.ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script>document.getElementById(\"btnShowImg\").value = \"隐藏县区数据\";</script>");
        }
        /// <summary>
        /// 不分地区汇总后的数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void HzButton1_Click(object sender, EventArgs e)
        {
            int t = 0;
            StringBuilder sb = new StringBuilder();
            string orderby = this.OrderFileds.SelectedValue + "  " + this.OrderType.SelectedValue;//排序字段与方式

            if (!string.IsNullOrEmpty(AreaControl1.SelectedAreaID) && AreaControl1.SelectedAreaID != "510000")
            {
                if (AreaControl1.SelectedAreaID.Length == 4)
                {
                    sb.AppendFormat(" AND areaid like '{0}%'", AreaControl1.SelectedAreaID);
                }
                else
                {
                    sb.AppendFormat(" AND areaid ='{0}'", AreaControl1.SelectedAreaID);
                }
            }
            if (!string.IsNullOrEmpty(txtProductName.Text.ToString()))
            {
                sb.AppendFormat(" and ProductName like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtProductName.Text.ToString()));
            }
            if (!string.IsNullOrEmpty(txtMedicineModel.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and MedicineModelName like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtMedicineModel.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtPack.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and Pack like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtPack.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtCompany_SC.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and CompanyName_SC like '%{0}%'", HZ.Supervise.DAL.DAL_Helper.Replace(txtCompany_SC.Text.ToString().Trim()));
            }
            if (!string.IsNullOrEmpty(txtUnit.Text.ToString().Trim()))
            {
                sb.AppendFormat(" and Unit = '{0}'", HZ.Supervise.DAL.DAL_Helper.Replace(txtUnit.Text.ToString().Trim()));
            }
            HZ.Supervise.IBLL.IExecuteContext iEC = HZ.Supervise.BLLFactory.ExecuteContext();
            System.Data.DataTable dt = iEC.getGoodsPSLList(1, sb.ToString(), orderby, 0, 0, out t);
            HZ.Supervise.Web.Function.ChangeRate_PS(dt, "DistributeRate");
            HZ.Supervise.Web.Function.ChangeRate(dt, "WareHouseRate");
            //HZ.Supervise.Web.Function.AddColumn(dt, "WareHouseRate", "SortSource");
            ExportFile.Instance.ExportData(dt, gvwGoodsTotal, this.Page);
        }
    }
}
